public class Solution5 {
    //121. 买卖股票的最佳时机
    public int maxProfit(int[] prices) {
        //f[i]表示第i天卖出
        //g[i]表示第i天买入 可以是持续买入
        int n = prices.length;
        int[] f = new int[n];
        int[] g = new int[n];
        g[0] = prices[0];
        for (int i = 1; i < n; i++) {
            f[i] = Math.max(prices[i]-g[i-1],f[i-1]);
            g[i] = Math.min(g[i-1],prices[i]);
        }
        return f[n-1];
    }
}
